package com.shixun.milktea.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.shixun.milktea.entity.Swiper;
import com.shixun.milktea.mapper.SwiperMapper;
import com.shixun.milktea.service.SwiperService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zrs
 * @since 2022-06-12
 */
@Service
public class SwiperServiceImpl extends ServiceImpl<SwiperMapper, Swiper> implements SwiperService {
    @Autowired
    SwiperMapper swiperMapper;

    /**
     * 轮播图上架
     * @param swiperId
     * @return
     * @throws Exception
     */
    @Override
    public int updateSwiperStatusUp(int swiperId) throws Exception {
        UpdateWrapper<Swiper> objectUpdateWrapper = new UpdateWrapper<>();
        objectUpdateWrapper.eq("swiper_id",swiperId);
        objectUpdateWrapper.set("swiper_status",1);
        int update = swiperMapper.update(null, objectUpdateWrapper);
        return update;
    }

    /**
     * 轮播图下架
     * @param swiperId
     * @return
     * @throws Exception
     */
    @Override
    public int updateSwiperStatusDown(int swiperId) throws Exception {
        UpdateWrapper<Swiper> objectUpdateWrapper = new UpdateWrapper<>();
        objectUpdateWrapper.eq("swiper_id",swiperId);
        objectUpdateWrapper.set("swiper_status",0);
        int update = swiperMapper.update(null, objectUpdateWrapper);
        return update;
    }
}
